﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Qplus.Commands;
using Qplus.beans;

namespace Qplus.UI
{
    public class HttpCommand_UI
    {
        QUser user = QplusT.Instance.getUser();

        private static HttpCommand_UI instance;

        public event EventHandler<HttpEvent> msgFromSever;

        HttpCommand_UI()
        {

        }
        public static HttpCommand_UI Instance { get { if (null == instance)instance = new HttpCommand_UI(); return instance; } }

        #region Friend Command
        public bool SearchFriend(string userName, string age, int sex, int pageNum)
        {
            SearchFriendCommand command = new SearchFriendCommand(user.userID, user.key);
            command.set(userName, age, sex, pageNum);
            command.execute(user.url);
            return true;
        }

        UserInfo friendInfo = new UserInfo();
        public bool AddFriend(int type, long friendID)
        {
            AddFriendCommand command = new AddFriendCommand(user.userID, user.key, user, friendInfo);
            command.set(type, friendID);
            command.execute(user.url);
            return true;
        }

        public bool DelFriend(int type, long friendID)
        {
            QUser user = QplusT.Instance.getUser();
            DelFriendCommand command = new DelFriendCommand(user.userID, user.key, user, friendInfo);
            command.set(type, friendID);
            command.execute(user.url);
            return true;
        }

        public bool GetFriend()
        {
            GetFriendCommand command = new GetFriendCommand(user.userID, user.key, friendInfo);
            command.set(friendInfo.getUserID());
            command.execute(user.url);
            return true;
        }

        public bool GetFriendList(int type)
        {
            GetFriendListCommand command = new GetFriendListCommand(user.userID.ToString(), System.Text.Encoding.UTF8.GetString(user.key, 0, user.key.Length), user);
            command.set(type);
            command.execute(user.url);
            return true;
        }

        public bool GetUserList(int type)
        {
            GetUserListCommand command = new GetUserListCommand(user.userID, user.key);
            //httpCMD = command;
            command.set(type);
            command.execute(user.url);
            return true;
        }
        #endregion

    }

    public class HttpEvent : EventArgs
    {
        public byte[] Message { get; private set; }

        public HttpEvent(string msg)
        {
            System.Diagnostics.Debug.WriteLine(msg);
        }

        public HttpEvent(byte[] msg)
        {
            Message = msg;
            System.Diagnostics.Debug.WriteLine(msg);
        }
    }
}
